package com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern;

import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.entity.MenuItem;
import com.suxiaoxiao.springbootlearn.designpattern.iteratorpattern.menu.Menu;

import java.util.Iterator;

/**
 * 招待员
 * @author 、
 */
public class Waitress {

    private Menu pancakeHouseMenu;
    private Menu dinerMenu;
    private Menu cafeMenu;

    public Waitress(Menu pancakeHouseMenu, Menu dinerMenu) {
        this(pancakeHouseMenu, dinerMenu, null);
    }

    public Waitress(Menu pancakeHouseMenu, Menu dinerMenu, Menu cafeMenu) {
        this.pancakeHouseMenu = pancakeHouseMenu;
        this.dinerMenu = dinerMenu;
        this.cafeMenu = cafeMenu;
    }

    /**
     * 打印菜单
     */
    public void printMenu() {
        Iterator pancakeIterator = pancakeHouseMenu.createIterator();
        Iterator dinerIterator = dinerMenu.createIterator();
        Iterator cafeIterator = cafeMenu.createIterator();
        System.out.println("MENU");
        System.out.println("----");
        System.out.println("BREAKFAST");
        printMenu(pancakeIterator);
        System.out.println("LUNCH");
        printMenu(dinerIterator);
        System.out.println("DINNER");
        printMenu(cafeIterator);
    }

    private void printMenu(Iterator iterator) {
        while (iterator.hasNext()) {
            MenuItem menuItem = (MenuItem) iterator.next();
            System.out.println(menuItem.getClass() + ",");
            System.out.println(menuItem.getPrice() + " -- ");
            System.out.println(menuItem.getDescription());
        }
    }

}
